﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using BLL;
using Model;
using CrystalDecisions.CrystalReports.Engine;

public partial class ProductAssemble_ViewAssemble_JointingCheck_JointingCheckbyDT : System.Web.UI.Page
{
    private IList<JointingCheckInfo> list;

    private DateTime dt1
    {
        get { return DateTime.Parse(ViewState["dt1"].ToString()); }
        set { ViewState["dt1"] = value; }
    }
    private DateTime dt2
    {
        get { return DateTime.Parse(ViewState["dt2"].ToString()); }
        set { ViewState["dt2"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Page.Unload += new EventHandler(Page_Unload);
        }
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void BindData()
    {
        JointingCheck test = new JointingCheck();
        list = test.GetJointingChecksbyDT(dt1, dt2);
        //GridView1.DataSource = list;
        //GridView1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        IList<JointingCheckInfo> list = GetQData();
        BindQCR(list);
        //BindData();
    }

    private void BindQCR(IList<JointingCheckInfo> list)
    {
        this.CrystalReportSource1.ReportDocument.Load(Server.MapPath("JointingCheckView.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text1"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        this.CrystalReportSource1.ReportDocument.SetDataSource(list);
        this.CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        this.CrystalReportViewer1.DataBind();
        this.CrystalReportViewer1.Visible = true;
    }

    private IList<JointingCheckInfo> GetQData()
    {
        IList<JointingCheckInfo> oprs = new List<JointingCheckInfo>();
        JointingCheck pt = new JointingCheck();
        oprs = pt.GetJointingChecksbyDT(dt1, dt2);
        return oprs;
    }

    //protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    this.GridView1.PageIndex = e.NewPageIndex;
    //    BindData();
    //}

    //protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    //{
    //    if (e.Row.RowType == DataControlRowType.Footer)
    //    {
    //        Label lbl = (Label)e.Row.FindControl("Label2");
    //        lbl.Text = list.Count.ToString();
    //    }
    //}
}
